package cn.aposoft.mq.kafka.admin.metrics;

import org.apache.kafka.clients.admin.Admin;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.Metric;
import org.apache.kafka.common.MetricName;

import java.util.Map;
import java.util.Properties;

public class PrintMetrics {
    public static void main(String[] args) {
        Properties p = new Properties();
        p.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "aposoft.cn:10091");// kafka地址，多个地址用逗号分割
        try (Admin admin = Admin.create(p);) {
            Map<MetricName, ? extends Metric> result = admin.metrics();
//            System.out.println(result);
            for (Metric metric : result.values()) {
                System.out.println(metric.metricName().name() + ":" + metric.metricValue());
            }
        }
    }
}
